﻿using System.Configuration;

namespace MySql.Simple.Mapper.Configuration
{
    /// <summary>
    /// The class that holds onto each monitor returned by the configuration manager.
    /// </summary>
    public class ConnectionElement : ConfigurationElement
    {
        private const string NameKey = "name";
        private const string ServerKey = "server";
        private const string PortKey = "port";
        private const string DatabaseKey = "database";
        private const string UsernameKey = "username";
        private const string PasswordKey = "password";

        [ConfigurationProperty(NameKey, IsKey = true, IsRequired = true)]
        public string Name
        {
            get { return (string)this[NameKey]; }
        }

        [ConfigurationProperty(ServerKey, IsKey = false, IsRequired = true)]
        public string Server
        {
            get { return (string)this[ServerKey]; }
        }

        [ConfigurationProperty(PortKey, IsKey = false, IsRequired = false, DefaultValue = 3306)]
        public int Port
        {
            get { return (int)this[PortKey]; }
        }

        [ConfigurationProperty(DatabaseKey, IsKey = false, IsRequired = true)]
        public string Database
        {
            get { return (string)this[DatabaseKey]; }
        }

        [ConfigurationProperty(UsernameKey, IsKey = false, IsRequired = false, DefaultValue = "root")]
        public string Username
        {
            get { return (string)this[UsernameKey]; }
        }

        [ConfigurationProperty(PasswordKey, IsKey = false, IsRequired = false, DefaultValue = "")]
        public string Password
        {
            get { return (string)this[PasswordKey]; }
        }
    }
}